<?php
/**
 * @version		$Id: default_body.php 2011.08.11 thierry $
 * @package		admin.views.servers.tmpl
 * @subpackage	com_projid
 * @copyright	Copyright (C) 2011 Pojid All rights reserved.
 * @license		GNU General Public License version 2 or later; see LICENSE.txt
 */
// No direct access to this file
defined('_JEXEC') or die('Restricted Access');
?>
<?php foreach($this->items as $i => $item): ?>
	<tr class="row<?php echo $i % 2; ?>">
		<td>
			<?php echo $item->id_serv; ?>
		</td>
		<td>
			<?php echo JHtml::_('grid.id', $i, $item->id_serv); ?>
		</td>
		<td>
			<a href="<?php echo JRoute::_('index.php?option=com_projid&task=server.edit&id_serv='.$item->id_serv);?>">
			<?php echo $this->escape($item->desc_serv); ?></a>
		</td>
		<td>
		<?PHP
		if ($item->driver=="postgres")
		{
			$item->requete="";
			require_once($_SERVER['DOCUMENT_ROOT']."/components/com_projid/models/mypostgresql.php");
			$postgres=new MyPostgreSQL($item);
			if ($postgres->Connection())
			{echo '<center><a class="jgrid"><span class="jgrid state publish"><span class="text">Connexion OK</span></a></center>';}
			else
			{echo '<center><a class="jgrid"><span class="state unpublish"><span class="text">Erreur de connection</span></a></center>';}
		}
		else
		{
			$option = array(
			'host' 		=> $item->host,
			'database'	=> $item->base,
			'user' 		=> $item->user,
			'password' 	=> $item->password,
			'driver' 	=> $item->driver
			//'prefix'	=> $item->prefix
			);
			
			$db = JDatabase::getInstance($option);

			if ($db->getErrorNum() > 0) {
				echo $db->getErrorMsg();
				echo '<center><a class="jgrid"><span class="state unpublish"><span class="text">Erreur de connection</span></a></center>';
				//JError::raiseError(500, JText::sprintf('JLIB_UTIL_ERROR_CONNECT_DATABASE', $db->getErrorNum(), $db->getErrorMsg()));
			}
			else
			{
				echo '<center><a class="jgrid"><span class="jgrid state publish"><span class="text">Connexion OK</span></a></center>';
			}
		}
		?>
		</td>
		<td>
			<?php echo $item->host; ?>
		</td>
		<td>
			<?php echo $item->base; ?>
		</td>
		<td>
			<?php echo $item->user; ?>
		</td>
		<td>
			<?php echo '*****';//$item->password; ?>
		</td>
		<td>
			<?php echo $item->driver; ?>
		</td>
	</tr>
<?php endforeach; ?>